#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QIcon icon(":/xue.png");
    ui->pushButton->setIcon(icon);

    //设置鼠标长时间点击，算连点
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);

//    //按钮绑定键盘
//    //这种方法可能会出现拼写错误，不好
//    //ui->pushButton_up->setShortcut(QKeySequence("ctrl+w"));   //多个快捷键一起按
//    ui->pushButton_up->setShortcut(QKeySequence("w"));      //如果同个按钮绑定多个快捷键，以最后一次的为准
//    ui->pushButton_down->setShortcut(QKeySequence("s"));
//    ui->pushButton_left->setShortcut(QKeySequence("a"));
//    ui->pushButton_right->setShortcut(QKeySequence("d"));

    //更好的写法
    //ui->pushButton_up->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_W));
    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));



    ui->label->setTextFormat(Qt::PlainText);
    ui->label_2->setTextFormat(Qt::RichText);
    ui->label_3->setTextFormat(Qt::MarkdownText);

    ui->label->setText("# <b>这是纯文本</b>");
    ui->label_2->setText("<b>这是富文本</b>");    //<b> 可以加粗区间文字
    ui->label_3->setText("# 这是markdown文本");

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect=ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
}

